package com.sanrenzu.chunbo.ui.fenlei.xiangqing;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.orhanobut.logger.Logger;
import com.sanrenzu.chunbo.R;
import com.sanrenzu.chunbo.adapter.XiangQingListViewAdapter;
import com.sanrenzu.chunbo.bean.zxb.DianJiTuPianBean;
import com.sanrenzu.chunbo.bean.zxb.ShouYeDianJiBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by My on 2016/9/1.
 */
public class XiangQingFragment extends Fragment implements XiangQingContract.View {

    //listview的显示
    @BindView(R.id.xiangqing_listview_fragment)
    ListView xiangqingListviewFragment;

    //listview适配器
    private XiangQingListViewAdapter xiangQingListViewAdapter;
    //persenter内部方法调用
    private XiangQingContract.Persenter xiangQingPersenter;
    // 黄油刀对象声明
    private Unbinder bind;


    public static XiangQingFragment newInstance(int tabIndex) {
        XiangQingFragment fragment = new XiangQingFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("tabIndex", tabIndex);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_xiangqing, container, false);
        xiangQingPersenter = new XiangQingPersenter(this);
        xiangQingPersenter.getVerticalShouYeBean();
        bind = ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void onGetVerticalShouYeDianJiBean(ShouYeDianJiBean shouYeDianJiBean) {
        List<DianJiTuPianBean> dianJiTuPianBean = shouYeDianJiBean.getProductContentImagesWH();
        xiangQingListViewAdapter = new XiangQingListViewAdapter(getActivity(),dianJiTuPianBean);
        xiangqingListviewFragment.setAdapter(xiangQingListViewAdapter);
    }

    @Override
    public void onGetVerticalFailed(String error) {
        Logger.d(error);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }
}
